<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>请求列表</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<link href="<?php echo base_url()?>media/css/style.css" type="text/css" rel="stylesheet"/>
	<link href="<?php echo base_url()?>media/css/jquery-ui-1.8.6.custom.css" type="text/css" rel="stylesheet"/>
	<link href="<?php echo base_url()?>media/css/ui.jqgrid.css" type="text/css" rel="stylesheet"/>
	<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/grid.locale-cn.js"></script>
	<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery.jqGrid.min.js"></script>
</head>
<body>
	<div class="form_div">
		<h5>请求列表</h5>
		<div id="select_frame" class="black_border">
			<div class="select_item" style="width:300px">
				<label>显示</label>
				<select name="requestGroup" style="width:140px" onchange="changeGroup()">
					<option value="1" <?php if($requestGroup==1) {echo "selected";}?>>我的所有请求列表</option>
					<option value="2" <?php if($requestGroup==2) {echo "selected";}?>>我的未处理请求列表</option>
				</select>
			</div>
			<input type=button value="新建" class="btn_60_24"  onclick="javascript:window.location.href='<?=base_url()?>innerUser/NewRequestByAgent';" style="margin:5px;"/>
			<div class="clear_both"></div>
		</div>

		<table id="list"></table>

		<div id="pager"></div>
	</div>
</body>
</html>
<script>
jQuery(document).ready(function(){
  $("#list").jqGrid({
    datatype: 'json',
	url:'<?php echo base_url()?>innerUser/AgentRequestData/?r=<?php echo $requestGroup;?>',
	mtype:'POST',
	height:'auto',
	width:'auto',
	jsonReader: {root:'rows',repeatitems:false},
    colNames:['编号','紧急程度', '状态','主题','请求类别','创建时间','上次更新时间'],
    colModel :[
      {name:'event_id', index:'event_id', width:80, sorttype:'int', formatter:formatLink},
      {name:'event_emergency_name', index:'event_emergency', width:70, align:'center', formatter:formatLink},
      {name:'event_status_name', index:'event_status', width:80, align:'center', sorttype:'float',formatter:formatStatus},
      {name:'event_title', index:'event_title', width:190, align:'left', sorttype:'float',formatter:formatEventTitle},
      {name:'event_type', index:'event_type', width:80, align:'left', sorttype:'float', formatter:formatLink},
      {name:'event_addtime', index:'event_addtime', width:100, sortable:false, formatter:formatLink},
      {name:'event_updatetime',index:'event_updatetime',width:100,sortable:true, formatter:formatLink} ],
    pager: '#pager',
    rowNum:20,
	sortorder:'desc',
    rowList:[20,30,40],
    viewrecords: true
  });
  function formatStatus(cellvalue, options, rowObject)
  {
  	var str = "";
	switch(rowObject.event_status)
	{
		case '26':
			var color = '';
			if(rowObject.event_emergency==5) {
				color = 'red';
				cellvalue = "！"+cellvalue;
			} else if(rowObject.event_emergency==4) {
				color = '#ff6600';
			} 
			str = '<span style="background-color:'+color+';display:block;color:#fff;">'+'<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>'+'</span>';
			break;
		/*case '27':
			str = '<span style="background-color:yellow;display:block;color:#fff;">'+cellvalue+'</span>';
			break;*/
		case '25':
			var color = '';
			var bgcolor = '#fff';
			if(rowObject.event_priority==5) {
				color = 'red';
				cellvalue = "！"+cellvalue;
			} else if(rowObject.event_priority==4) {
				color = '#ff6600';
				if(rowObject.level==3) {
					color = 'red';
				}
			}  else{			
				if(rowObject.level==3) {
					color = 'red';
				} else if(rowObject.level==2) {
					color = 'yellow';
					bgcolor = '#000';
				}
			}
			str = color=='' ? cellvalue : '<span style="background-color:'+color+';display:block;color:'+bgcolor+';">'+'<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>'+'</span>';
			
			break;
		case '27':
			str = '<span style="background-color:#129912;display:block;color:#fff;">'+'<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>'+'</span>';
			break;
		case '28':
			str = '<span style="background-color:#cfcfcf;display:block;color:#fff;">'+'<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>'+'</span>';
			break;
		default:
			str = '<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>';
	}
	
	//if(rowObject.event_status==26)
	//{
		//return '<span style="background-color:green;display:block;color:#fff;">'+cellvalue+'</span>';
	//}else{
	//	return cellvalue;
	//};
	return str;
  }
  function formatLink(cellvalue, options, rowObject)
  {
  	if(rowObject.event_id==cellvalue) {
		return '<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+cellvalue+'">'+'SJ'+pad(cellvalue, 8, '0', 1)+'</a>';
	}
	return '<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'">'+cellvalue+'</a>';
  }
  function formatEventTitle(cellvalue, options, rowObject)
  {
  	return '<span style="display:block;" title="'+rowObject.event_desc_sub+'">'+'<a href="<?=base_url()?>innerUser/ViewRequestByAgent/?eventId='+rowObject.event_id+'" style="display:block;">'+cellvalue+'</a>'+'</span>';
  }
});
function changeGroup()
{
	window.location.href='<?=base_url()?>innerUser/AgentRequestList/?r='+$("select[name='requestGroup']").val();
}
function pad(str, len, pad, dir)
{
	var STR_PAD_LEFT = 1;
	var STR_PAD_RIGHT = 2;
	var STR_PAD_BOTH = 3;

	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = ' '; }
	if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }

	if (len + 1 >= str.length) {

		switch (dir){

			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break;

			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;

			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break;

		} // switch

	}

	return str;

}
</script>
